package com.naizhuai.ui.mianbusiness.setting;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.naizhuai.MainActivity;
import com.naizhuai.Model.db.user.PersonUserBean;
import com.naizhuai.R;
import com.naizhuai.network.exception.ApiException;
import com.naizhuai.ui.adapter.ChosenChargeJoinAdapterHolder;
import com.naizhuai.ui.adapter.ThankChosenUserAdapterHolder;
import com.naizhuai.ui.components.swipeback.SwipeBackActivity;
import com.naizhuai.ui.entity.mainbusiness.ActionSubmitScanDetailsBean;
import com.naizhuai.ui.mianbusiness.action.presenter.ActionManageApiStoreIml;
import com.naizhuai.ui.mianbusiness.presenter.PublicDataApiStoreIml;
import com.naizhuai.util.ConstantsState;
import com.naizhuai.util.DialogUtils;
import com.naizhuai.util.IntentUtils;
import com.naizhuai.util.ListUtils;
import com.naizhuai.util.NaizhuAILog;
import com.naizhuai.util.UidUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Observer;
import rx.Subscription;

/**
 * 反馈界面
 */
public class SuggestActivity extends SwipeBackActivity implements View.OnClickListener {
    private static final String TAG = "SuggestActivity";

    @BindView(R.id.suggest_content)
    EditText suggestTxt;
    private Subscription submitSub;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @OnClick({R.id.base_back_icon, R.id.submit_suggest})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.base_back_icon:
                finish();
                break;
            case R.id.submit_suggest:
                if (TextUtils.isEmpty(suggestTxt.getText().toString())) {
                    shortToast(getString(R.string.suggestion_error));
                } else {
                    submitSub=PublicDataApiStoreIml.getInstance().postSuggestion(suggestTxt.getText().toString()).subscribe(new Observer<String>() {
                        @Override
                        public void onCompleted() {

                        }

                        @Override
                        public void onError(Throwable e) {
                            hideWaitDialog();
                            ApiException.showException(e, SuggestActivity.this,true);
                        }

                        @Override
                        public void onNext(String s) {
                            hideWaitDialog();
                            IntentUtils.startActivity(SuggestActivity.this, SuggestSuccessActivity.class);
                            finish();
                        }
                    });
                    showWaitDiaLog(submitSub);
                }
                break;
        }
    }

    @Override
    public void onBackPressedWithoutDialog() {
        DialogUtils.showSureDialog(this, getString(R.string.lost_data), dialog -> finish());
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_suggest_layout;
    }

}
